﻿/// ****************************************************************************
/// Author:	        Robin Zhu
/// Create Date:	2012-4-28
/// Purpose: 		角色与权限绑定关系集合类
/// ****************************************************************************
/// Modify By		Date			Remark
/// Robin           2015-2-26       增加GetRoles方法
/// ****************************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RB.Domain.RelationalMapping;

namespace RB.Web.Security.Rdb
{
    public class RolePermissionSet : RecordSet<RolePermission>
    {
        internal string[] GetPermCodesByRoles(Guid[] roles)
        {
            if (roles != null && roles.Length > 0)
            {
                var q = from t in this.AsQueryable()
                        where roles.Contains(t.RoleId)
                        select t.PermCode;
                return q.ToArray();
            }
            return new string[0];
        }

        internal string[] GetRoles(string permCode)
        {
            var q = from t in this.AsQueryable()
                    join t1 in (new UserRoleSet()).AsQueryableNoOrder() on t.RoleId equals t1.Id
                    where t.PermCode == permCode
                    select t1.Code;
            return q.ToArray();
        }
    }
}
